package Dome3;

import java.util.Arrays;

public class Text3 {
    public static void main(String[] args) {
        Student wang = new Student("wang", 200);
        Student li = new Student("li", 19);
        Student hu = new Student("hu", 11);
        Student[] students ={wang,li,hu};
//        Arrays.sort(students);
         bsort(students);
        System.out.println(Arrays.toString(students));
    }
    public static void bsort(Comparable[] comparables){
        for (int i = 0; i < comparables.length - 1; i++) {
            for (int j = 0; j < comparables.length - 1 - i; j++) {
                if(comparables[j].compareTo(comparables[j+1])>0){
                    Comparable tmp=comparables[j];
                    comparables[j]=comparables[j+1];
                    comparables[j+1]=tmp;
                }
            }
        }
    }
}

class Student implements Comparable<Student>{
    String name;
    int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public int compareTo(Student o) {
        if(this.age>o.age){
            return 1;
        } else if (this.age < o.age) {
            return -1;
        }else {
            return 0;
        }
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

